home *** CD-ROM | disk | FTP | other *** search
/ Openstep 4.2 (Developer) / Openstep Developer 4.2.iso / NextDeveloper / Source / GNU / uucp / Uucp.framework / sysdep.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-20  |  16.0 KB  |  564 lines

  1. /* sysh.unx -*- C -*-
  2.    The header file for the UNIX system dependent routines.
  3.  
  4.    Copyright (C) 1991, 1992, 1993, 1995 Ian Lance Taylor
  5.  
  6.    This file is part of the Taylor UUCP package.
  7.  
  8.    This program is free software; you can redistribute it and/or
  9.    modify it under the terms of the GNU General Public License as
  10.    published by the Free Software Foundation; either version 2 of the
  11.    License, or (at your option) any later version.
  12.  
  13.    This program is distributed in the hope that it will be useful, but
  14.    WITHOUT ANY WARRANTY; without even the implied warranty of
  15.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.    General Public License for more details.
  17.  
  18.    You should have received a copy of the GNU General Public License
  19.    along with this program; if not, write to the Free Software
  20.    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  21.  
  22.    The author of the program may be contacted at ian@airs.com or
  23.    c/o Cygnus Support, 48 Grove Street, Somerville, MA 02144.
  24.    */
  25.  
  26. #ifndef SYSH_UNX_H
  27.  
  28. #define SYSH_UNX_H
  29.  
  30. #if ANSI_C
  31. /* These structures are used in prototypes but are not defined in this
  32.    header file.  */
  33. struct uuconf_system;
  34. struct sconnection;
  35. #endif
  36.  
  37. /* SCO, SVR4 and Sequent lockfiles are basically just like HDB
  38.    lockfiles.  */
  39. #if HAVE_SCO_LOCKFILES || HAVE_SVR4_LOCKFILES || HAVE_SEQUENT_LOCKFILES
  40. #undef HAVE_HDB_LOCKFILES
  41. #define HAVE_HDB_LOCKFILES 1
  42. #endif
  43.  
  44. #if HAVE_BSD_TTY + HAVE_SYSV_TERMIO + HAVE_POSIX_TERMIOS != 1
  45.  #error Terminal driver define not set or duplicated
  46. #endif
  47.  
  48. #if SPOOLDIR_V2 + SPOOLDIR_BSD42 + SPOOLDIR_BSD43 + SPOOLDIR_HDB + SPOOLDIR_ULTRIX + SPOOLDIR_SVR4 + SPOOLDIR_TAYLOR != 1
  49.  #error Spool directory define not set or duplicated
  50. #endif
  51.  
  52. /* If setreuid is broken, don't use it.  */
  53. #if HAVE_BROKEN_SETREUID
  54. #undef HAVE_SETREUID
  55. #define HAVE_SETREUID 0
  56. #endif
  57.  
  58. /* Get some standard types from the configuration header file.  */
  59. #ifdef PID_T
  60. typedef PID_T pid_t;
  61. #endif
  62.  
  63. #ifdef UID_T
  64. typedef UID_T uid_t;
  65. #endif
  66.  
  67. #ifdef GID_T
  68. typedef GID_T gid_t;
  69. #endif
  70.  
  71. #ifdef OFF_T
  72. typedef OFF_T off_t;
  73. #endif
  74.  
  75. /* On Unix, binary files are the same as text files.  */
  76. #define BINREAD "r"
  77. #define BINWRITE "w"
  78.  
  79. /* If we have sigaction, we can force system calls to not be
  80.    restarted.  */
  81. #if HAVE_SIGACTION
  82. #undef HAVE_RESTARTABLE_SYSCALLS
  83. #define HAVE_RESTARTABLE_SYSCALLS 0
  84. #endif
  85.  
  86. /* If we have sigvec, and we have HAVE_SIGVEC_SV_FLAGS, and
  87.    SV_INTERRUPT is defined, we can force system calls to not be
  88.    restarted (signal.h is included by uucp.h before this point, so
  89.    SV_INTERRUPT will be defined by now if it it ever is).  */
  90. #if HAVE_SIGVEC && HAVE_SIGVEC_SV_FLAGS
  91. #ifdef SV_INTERRUPT
  92. #undef HAVE_RESTARTABLE_SYSCALLS
  93. #define HAVE_RESTARTABLE_SYSCALLS 0
  94. #endif
  95. #endif
  96.  
  97. /* If we were cross-configured, we will have a value of -1 for
  98.    HAVE_RESTARTABLE_SYSCALLS.  In this case, we try to guess what the
  99.    correct value should be.  Yuck.  If we have sigvec, but neither of
  100.    the above cases applied (which we know because they would have
  101.    changed HAVE_RESTARTABLE_SYSCALLS) then we are probably on 4.2BSD
  102.    and system calls are automatically restarted.  Otherwise, assume
  103.    that they are not.  */
  104. #if HAVE_RESTARTABLE_SYSCALLS == -1
  105. #undef HAVE_RESTARTABLE_SYSCALLS
  106. #if HAVE_SIGVEC
  107. #define HAVE_RESTARTABLE_SYSCALLS 1
  108. #else
  109. #define HAVE_RESTARTABLE_SYSCALLS 0
  110. #endif
  111. #endif /* HAVE_RESTARTABLE_SYSCALLS == -1 */
  112.  
  113. /* We don't handle sigset in combination with restartable system
  114.    calls, so we check for it although this combination will never
  115.    happen.  */
  116. #if ! HAVE_SIGACTION && ! HAVE_SIGVEC && HAVE_SIGSET
  117. #if HAVE_RESTARTABLE_SYSCALLS
  118. #undef HAVE_SIGSET
  119. #define HAVE_SIGSET 0
  120. #endif
  121. #endif
  122.  
  123. /* If we don't have restartable system calls, we can ignore
  124.    fsysdep_catch, usysdep_start_catch and usysdep_end_catch.
  125.    Otherwise fsysdep_catch has to do a setjmp.  */
  126.  
  127. #if ! HAVE_RESTARTABLE_SYSCALLS
  128.  
  129. #define fsysdep_catch() (TRUE)
  130. #define usysdep_start_catch()
  131. #define usysdep_end_catch()
  132. #define CATCH_PROTECT
  133.  
  134. #else /* HAVE_RESTARTABLE_SYSCALLS */
  135.  
  136. #if HAVE_SETRET && ! HAVE_SIGSETJMP
  137. #include <setret.h>
  138. #define setjmp setret
  139. #define longjmp longret
  140. #define jmp_buf ret_buf
  141. #else /* ! HAVE_SETRET || HAVE_SIGSETJMP */
  142. #include <setjmp.h>
  143. #if HAVE_SIGSETJMP
  144. #undef setjmp
  145. #undef longjmp
  146. #undef jmp_buf
  147. #define setjmp(s) sigsetjmp ((s), TRUE)
  148. #define longjmp siglongjmp
  149. #define jmp_buf sigjmp_buf
  150. #endif /* HAVE_SIGSETJMP */
  151. #endif /* ! HAVE_SETRET || HAVE_SIGSETJMP */
  152.  
  153. extern volatile sig_atomic_t fSjmp;
  154. extern volatile jmp_buf sSjmp_buf;
  155.  
  156. #define fsysdep_catch() (setjmp (sSjmp_buf) == 0)
  157.  
  158. #define usysdep_start_catch() (fSjmp = TRUE)
  159.  
  160. #define usysdep_end_catch() (fSjmp = FALSE)
  161.  
  162. #define CATCH_PROTECT volatile
  163.  
  164. #endif /* HAVE_RESTARTABLE_SYSCALLS */
  165.  
  166. /* Get definitions for the terminal driver.  */
  167.  
  168. #if HAVE_BSD_TTY
  169. #include <sgtty.h>
  170. struct sbsd_terminal
  171. {
  172.   struct sgttyb stty;
  173.   struct tchars stchars;
  174.   struct ltchars sltchars;
  175. };
  176. typedef struct sbsd_terminal sterminal;
  177. #define fgetterminfo(o, q) \
  178.   (ioctl ((o), TIOCGETP, &(q)->stty) == 0 \
  179.    && ioctl ((o), TIOCGETC, &(q)->stchars) == 0 \
  180.    && ioctl ((o), TIOCGLTC, &(q)->sltchars) == 0)
  181. #define fsetterminfo(o, q) \
  182.   (ioctl ((o), TIOCSETN, &(q)->stty) == 0 \
  183.    && ioctl ((o), TIOCSETC, &(q)->stchars) == 0 \
  184.    && ioctl ((o), TIOCSLTC, &(q)->sltchars) == 0)
  185. #define fsetterminfodrain(o, q) \
  186.   (ioctl ((o), TIOCSETP, &(q)->stty) == 0 \
  187.    && ioctl ((o), TIOCSETC, &(q)->stchars) == 0 \
  188.    && ioctl ((o), TIOCSLTC, &(q)->sltchars) == 0)
  189. #endif /* HAVE_BSD_TTY */
  190.  
  191. #if HAVE_SYSV_TERMIO
  192. #include <termio.h>
  193. typedef struct termio sterminal;
  194. #define fgetterminfo(o, q) (ioctl ((o), TCGETA, (q)) == 0)
  195. #define fsetterminfo(o, q) (ioctl ((o), TCSETA, (q)) == 0)
  196. #define fsetterminfodrain(o, q) (ioctl ((o), TCSETAW, (q)) == 0)
  197. #endif /* HAVE_SYSV_TERMIO */
  198.  
  199. #if HAVE_POSIX_TERMIOS
  200. #include <termios.h>
  201. typedef struct termios sterminal;
  202. #define fgetterminfo(o, q) (tcgetattr ((o), (q)) == 0)
  203. #define fsetterminfo(o, q) (tcsetattr ((o), TCSANOW, (q)) == 0)
  204. #define fsetterminfodrain(o, q) (tcsetattr ((o), TCSADRAIN, (q)) == 0)
  205.  
  206. /* On some systems it is not possible to include both <sys/ioctl.h>
  207.    and <termios.h> in the same source files; I don't really know why.
  208.    On such systems, we pretend that we don't have <sys/ioctl.h>.  */
  209. #if ! HAVE_TERMIOS_AND_SYS_IOCTL_H
  210. #undef HAVE_SYS_IOCTL_H
  211. #define HAVE_SYS_IOCTL_H 0
  212. #endif
  213.  
  214. #endif /* HAVE_POSIX_TERMIOS */
  215.  
  216. /* The root directory (this is needed by the system independent stuff
  217.    as the default for local-send).  */
  218. #define ZROOTDIR "/"
  219.  
  220. /* The name of the execution directory within the spool directory
  221.    (this is need by the system independent uuxqt.c).  */
  222. #define XQTDIR ".Xqtdir"
  223.  
  224. /* The name of the directory in which we preserve file transfers that
  225.    failed.  */
  226. #define PRESERVEDIR ".Preserve"
  227.  
  228. /* The name of the directory to which we move corrupt files.  */
  229. #define CORRUPTDIR ".Corrupt"
  230.  
  231. /* The name of the directory to which we move failed execution files.  */
  232. #define FAILEDDIR ".Failed"
  233.  
  234. /* The length of the sequence number used in a file name.  */
  235. #define CSEQLEN (4)
  236.  
  237. /* Get some standard definitions.  Avoid including the files more than
  238.    once--some might have been included by uucp.h.  */
  239. #if USE_STDIO && HAVE_UNISTD_H
  240. #include <unistd.h>
  241. #endif
  242. #if ! USE_TYPES_H
  243. #include <sys/types.h>
  244. #endif
  245. #include <sys/stat.h>
  246.  
  247. /* Get definitions for the file permission bits.  */
  248.  
  249. #ifndef S_IRWXU
  250. #define S_IRWXU 0700
  251. #endif
  252. #ifndef S_IRUSR
  253. #define S_IRUSR 0400
  254. #endif
  255. #ifndef S_IWUSR
  256. #define S_IWUSR 0200
  257. #endif
  258. #ifndef S_IXUSR
  259. #define S_IXUSR 0100
  260. #endif
  261.  
  262. #ifndef S_IRWXG
  263. #define S_IRWXG 0070
  264. #endif
  265. #ifndef S_IRGRP
  266. #define S_IRGRP 0040
  267. #endif
  268. #ifndef S_IWGRP
  269. #define S_IWGRP 0020
  270. #endif
  271. #ifndef S_IXGRP
  272. #define S_IXGRP 0010
  273. #endif
  274.  
  275. #ifndef S_IRWXO
  276. #define S_IRWXO 0007
  277. #endif
  278. #ifndef S_IROTH
  279. #define S_IROTH 0004
  280. #endif
  281. #ifndef S_IWOTH
  282. #define S_IWOTH 0002
  283. #endif
  284. #ifndef S_IXOTH
  285. #define S_IXOTH 0001
  286. #endif
  287.  
  288. #if STAT_MACROS_BROKEN
  289. #undef S_ISDIR
  290. #endif
  291.  
  292. #ifndef S_ISDIR
  293. #ifdef S_IFDIR
  294. #define S_ISDIR(i) (((i) & S_IFMT) == S_IFDIR)
  295. #else /* ! defined (S_IFDIR) */
  296. #define S_ISDIR(i) (((i) & 0170000) == 040000)
  297. #endif /* ! defined (S_IFDIR) */
  298. #endif /* ! defined (S_ISDIR) */
  299.  
  300. /* We need the access macros.  */
  301. #ifndef R_OK
  302. #define R_OK 4
  303. #define W_OK 2
  304. #define X_OK 1
  305. #define F_OK 0
  306. #endif /* ! defined (R_OK) */
  307.  
  308. /* We create files with these modes (should this be configurable?).  */
  309. #define IPRIVATE_FILE_MODE (S_IRUSR | S_IWUSR)
  310. #define IPUBLIC_FILE_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
  311.  
  312. /* We create directories with this mode (should this be configurable?).  */
  313. #define IDIRECTORY_MODE (S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)
  314. #define IPUBLIC_DIRECTORY_MODE (S_IRWXU | S_IRWXG | S_IRWXO)
  315.  
  316. #if ! HAVE_OPENDIR
  317.  
  318. /* Define some structures to use if we don't have opendir, etc.  These
  319.    will only work if we have the old Unix filesystem, with a 2 byte
  320.    inode and a 14 byte filename.  */
  321.  
  322. #include <sys/dir.h>
  323.  
  324. struct dirent
  325. {
  326.   char d_name[DIRSIZ + 1];
  327. };
  328.  
  329. typedef struct
  330. {
  331.   int o;
  332.   struct dirent s;
  333. } DIR;
  334.  
  335. extern DIR *opendir P((const char *zdir));
  336. extern struct dirent *readdir P((DIR *));
  337. extern int closedir P((DIR *));
  338.  
  339. #endif /* ! HAVE_OPENDIR */
  340.  
  341. #if ! HAVE_FTW_H
  342.  
  343. /* If there is no <ftw.h>, define the ftw constants.  */
  344.  
  345. #define FTW_F (0)
  346. #define FTW_D (1)
  347. #define FTW_DNR (2)
  348. #define FTW_NS (3)
  349.  
  350. #endif /* ! HAVE_FTW_H */
  351.  
  352. /* This structure holds the system dependent information we keep for a
  353.    connection.  This is used by the TCP and TLI code.  */
  354.  
  355. struct ssysdep_conn
  356. {
  357.   /* File descriptor.  */
  358.   int o;
  359.   /* File descriptor to read from (used by stdin and pipe port types).  */
  360.   int ord;
  361.   /* File descriptor to write to (used by stdin and pipe port types).  */
  362.   int owr;
  363.   /* Device name.  */
  364.   char *zdevice;
  365.   /* File status flags.  */
  366.   int iflags;
  367.   /* File status flags for write descriptor (-1 if not used).  */
  368.   int iwr_flags;
  369.   /* Hold the real descriptor when using a dialer device.  */
  370.   int ohold;
  371.   /* TRUE if this is a terminal and the remaining fields are valid.  */
  372.   boolean fterminal;
  373.   /* TRUE if this is a TLI descriptor.  */
  374.   boolean ftli;
  375.   /* Baud rate.  */
  376.   long ibaud;
  377.   /* Original terminal settings.  */
  378.   sterminal sorig;
  379.   /* Current terminal settings.  */
  380.   sterminal snew;
  381.   /* Process ID of currently executing pipe command, or parent process
  382.      of forked TCP or TLI server, or -1.  */
  383.   pid_t ipid;
  384. #if HAVE_COHERENT_LOCKFILES
  385.   /* On Coherent we need to hold on to the real port name which will
  386.      be used to enable the port.  Ick.  */
  387.   char *zenable;
  388. #endif
  389. };
  390.  
  391. /* These functions do I/O and chat scripts to a port.  They are called
  392.    by the TCP and TLI routines.  */
  393. extern boolean fsysdep_conn_read P((struct sconnection *qconn,
  394.                     char *zbuf, size_t *pclen,
  395.                     size_t cmin, int ctimeout,
  396.                     boolean freport));
  397. extern boolean fsysdep_conn_write P((struct sconnection *qconn,
  398.                      const char *zbuf, size_t clen));
  399. extern boolean fsysdep_conn_io P((struct sconnection *qconn,
  400.                   const char *zwrite, size_t *pcwrite,
  401.                   char *zread, size_t *pcread));
  402. extern boolean fsysdep_conn_chat P((struct sconnection *qconn,
  403.                     char **pzprog));
  404.  
  405. /* Set a signal handler.  */
  406. extern void usset_signal P((int isig, RETSIGTYPE (*pfn) P((int)),
  407.                 boolean fforce, boolean *pfignored));
  408.  
  409. /* Default signal handler.  This sets the appropriate element of the
  410.    afSignal array.  If system calls are automatically restarted, it
  411.    may do a longjmp to an fsysdep_catch.  */
  412. extern RETSIGTYPE ussignal P((int isig));
  413.  
  414. /* Try to fork, repeating several times.  */
  415. extern pid_t ixsfork P((void));
  416.  
  417. /* Spawn a job.  Returns the process ID of the spawned job or -1 on
  418.    error.  The following macros may be passed in aidescs.  */
  419.  
  420. /* Set descriptor to /dev/null.  */
  421. #define SPAWN_NULL (-1)
  422. /* Set element of aidescs to a pipe for caller to read from.  */
  423. #define SPAWN_READ_PIPE (-2)
  424. /* Set element of aidescs to a pipe for caller to write to.  */
  425. #define SPAWN_WRITE_PIPE (-3)
  426.  
  427. extern pid_t ixsspawn P((const char **pazargs, int *aidescs,
  428.              boolean fkeepuid, boolean fkeepenv,
  429.              const char *zchdir, boolean fnosigs,
  430.              boolean fshell, const char *zpath,
  431.              const char *zuu_machine,
  432.              const char *zuu_user));
  433.  
  434. /* Do a form of popen using ixsspawn.  */
  435. extern FILE *espopen P((const char **pazargs, boolean frd,
  436.             pid_t *pipid));
  437.  
  438. /* Wait for a particular process to finish, returning the exit status.
  439.    The process ID should be pid_t, but we can't put that in a
  440.    prototype.  */
  441. extern int ixswait P((unsigned long ipid, const char *zreport));
  442.  
  443. /* Read from a connection using two file descriptors.  */
  444. extern boolean fsdouble_read P((struct sconnection *qconn, char *zbuf,
  445.                 size_t *pclen, size_t cmin, int ctimeout,
  446.                 boolean freport));
  447.  
  448. /* Write to a connection using two file descriptors.  */
  449. extern boolean fsdouble_write P((struct sconnection *qconn,
  450.                  const char *zbuf, size_t clen));
  451.  
  452. /* Run a chat program on a connection using two file descriptors.  */
  453. extern boolean fsdouble_chat P((struct sconnection *qconn,
  454.                 char **pzprog));
  455.  
  456. /* Find a spool file in the spool directory.  For a local file, the
  457.    bgrade argument is the grade of the file.  This is needed for
  458.    SPOOLDIR_SVR4.  */
  459. extern char *zsfind_file P((const char *zsimple, const char *zsystem,
  460.                 int bgrade));
  461.  
  462. /* Return the grade given a sequence number.  */
  463. extern int bsgrade P((pointer pseq));
  464.  
  465. /* Lock a string.  */
  466. extern boolean fsdo_lock P((const char *, boolean fspooldir,
  467.                 boolean *pferr));
  468.  
  469. /* Unlock a string.  */
  470. extern boolean fsdo_unlock P((const char *, boolean fspooldir));
  471.  
  472. /* Check access for a particular user name, or NULL to check access
  473.    for any user.  */
  474. extern boolean fsuser_access P((const struct stat *, int imode,
  475.                 const char *zuser));
  476.  
  477. /* Switch to the permissions of the invoking user.  This sets the
  478.    argument to a value to pass to fsuucp_perms.  */
  479. extern boolean fsuser_perms P((uid_t *));
  480.  
  481. /* Switch back to the permissions of the UUCP user ID.  This should be
  482.    passed the value returned by fsuser_perms in its argument.  */
  483. extern boolean fsuucp_perms P((long));
  484.  
  485. /* Stick two directories and a file name together.  */
  486. extern char *zsappend3 P((const char *zdir1, const char *zdir2,
  487.               const char *zfile));
  488.  
  489. /* Stick three directories and a file name together.  */
  490. extern char *zsappend4 P((const char *zdir1, const char *zdir2,
  491.               const char *zdir3, const char *zfile));
  492.  
  493. /* Get a temporary file name.  */
  494. extern char *zstemp_file P((const struct uuconf_system *qsys));
  495.  
  496. /* Get a command file name.  */
  497. extern char *zscmd_file P((const struct uuconf_system *qsys, int bgrade));
  498.  
  499. /* Get a jobid from a system, a file name, and a grade.  */
  500. extern char *zsfile_to_jobid P((const struct uuconf_system *qsys,
  501.                 const char *zfile,
  502.                 int bgrade));
  503.  
  504. /* Get a file name from a jobid.  This also returns the associated system
  505.    in *pzsystem and the grade in *pbgrade.  */
  506. extern char *zsjobid_to_file P((const char *zid, char **pzsystem,
  507.                 char *pbgrade));
  508.  
  509. /* See whether there is a spool directory for a system when using
  510.    SPOOLDIR_ULTRIX.  */
  511. extern boolean fsultrix_has_spool P((const char *zsystem));
  512.  
  513. #if HAVE_COHERENT_LOCKFILES
  514. /* Lock a coherent tty.  */
  515. extern boolean lockttyexist P((const char *z));
  516. extern boolean fscoherent_disable_tty P((const char *zdevice,
  517.                      char **pzenable));
  518. #endif
  519.  
  520. /* Some replacements for standard Unix functions.  */
  521.  
  522. #if ! HAVE_DUP2
  523. extern int dup2 P((int oold, int onew));
  524. #endif
  525.  
  526. #if ! HAVE_FTW
  527. extern int ftw P((const char *zdir,
  528.           int (*pfn) P((const char *zfile,
  529.                 struct stat *qstat,
  530.                 int iflag)),
  531.           int cdescriptors));
  532. #endif
  533.  
  534. #if ! HAVE_GETCWD && ! HAVE_GETWD
  535. extern char *getcwd P((char *zbuf, size_t cbuf));
  536. #endif
  537.  
  538. #if ! HAVE_MKDIR
  539. extern int mkdir P((const char *zdir, int imode));
  540. #endif
  541.  
  542. #if ! HAVE_RENAME
  543. extern int rename P((const char *zold, const char *znew));
  544. #endif
  545.  
  546. #if ! HAVE_RMDIR
  547. extern int rmdir P((const char *zdir));
  548. #endif
  549.  
  550. /* The working directory from which the program was run (this is set
  551.    by usysdep_initialize if called with INIT_GETCWD).  */
  552. extern char *zScwd;
  553.  
  554. /* The spool directory name.  */
  555. extern const char *zSspooldir;
  556.  
  557. /* The lock directory name.  */
  558. extern const char *zSlockdir;
  559.  
  560. /* The local UUCP name (needed for some spool directory stuff).  */
  561. extern const char *zSlocalname;
  562.  
  563. #endif /* ! defined (SYSH_UNX_H) */
  564.